package com.umxwe.kill.seckill.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.umxwe.kill.seckill.domain.KillInfo;
import com.umxwe.kill.seckill.dto.OrderInfoDto;
import com.umxwe.kill.seckill.feign.RemoteKillInfoService;
import com.umxwe.kill.seckill.mapper.KillInfoMapper;
import com.umxwe.kill.seckill.service.KillInfoService;
import com.umxwe.kill.seckill.vo.killInfoVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class KillInfoServiceImpl implements KillInfoService {

    @Resource
    private KillInfoMapper killInfoMapper;


    @Resource
    private RemoteKillInfoService remoteKillInfoService;

    @Override
    public killInfoVo getOne(Long id) {
        KillInfo one = killInfoMapper.getOne(id);
        String orderStr = remoteKillInfoService.getOrderInfo();
        OrderInfoDto orderInfo = JSONObject.parseObject(orderStr, OrderInfoDto.class);
        return new killInfoVo(){{
            setId(one.getId());
            setStartTime(one.getStartTime());
            setEndTime(one.getEndTime());
            setItemId(one.getItemId());
            setNumber(orderInfo.getNumber());
            setReceiverName(orderInfo.getReceiverName());
            setReceiverPhone(orderInfo.getReceiverPhone());
            setReceiverAddr(orderInfo.getReceiverAddr());
            setUserId(orderInfo.getUserId());
            setUserName(orderInfo.getUserName());
        }};
    }
}
